package com.rpframework.module.common.bottom.listener;

import com.rpframework.module.common.bottom.entity.Jurisdiction;
import com.rpframework.module.common.bottom.service.JurisdictionService;
import com.rpframework.module.common.url.explain.RequestDescriptionExplain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import java.util.List;

/**
 * 访问接口检查
 * Created by jump on 2016/7/13.
 */
public class AccessInterfaceInspect implements
        ApplicationListener<ContextRefreshedEvent> {
    @Autowired
    private JurisdictionService jurisdictionService;

    public AccessInterfaceInspect(String[] controllerPackage) {
        this.controllerPackage = controllerPackage;
    }

    /**
     * 控制层扫描包
     */
    private String[] controllerPackage;

    public String[] getControllerPackage() {
        return controllerPackage;
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        RequestDescriptionExplain requestDescriptionExplain = new RequestDescriptionExplain(
                getControllerPackage());
        List<Jurisdiction> list = requestDescriptionExplain.getUrlAll();
        jurisdictionService.adds(list);
    }
}
